import React, { useEffect, useState } from 'react';
import axios from 'axios'
import PropTypes from 'prop-types';
interface IProps {
  method: string;
  url: string;
}

const useData = (props: IProps) => {
  const [data, setData] = useState()
  const [loading, setLoading] = useState(false)
  const { method, url } = props;
  useEffect(() => {
    setLoading(true);
    (axios as any)[method](url).then((response: any) => {
      console.log(response, 'response')
      if (response.data) {
        setLoading(false)
        setData(data)
      }
    })
  }, [])
  return [data, loading]
}

useData.defaultProps = {
  method: 'get'
};

export default useData;
